package com.rppowell.pixie.swing.importer;

import java.awt.Graphics;
import java.awt.Insets;
import java.awt.image.BufferedImage;

import javax.swing.JPanel;

public class SpritePreviewPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private BufferedImage image;
	
	public void paint(Graphics g) {
		super.paintComponent(g);;
		super.paintBorder(g);
		Insets in = this.getInsets();
		int w = this.getWidth() - in.right - in.left - 1;
		int h = this.getHeight() - in.top - in.bottom - 1;
		
		if (image != null) {
			int i = (w-image.getWidth())/2;
			int j = (h-image.getHeight())/2;
			g.drawImage(image, i, j, null);
		}
	}
	
	public BufferedImage getImage() {
		return image;
	}
	
	public void setImage(BufferedImage image) {
		this.image = image;
		this.revalidate();
		this.repaint();
	}
}
